(function($){

    $.fn.extend({
        submitter : function(options, arg) {
            if (typeof(options) == "object") {
                options = $.extend({}, $.submitter.defaults, options);
            }
            this.each(function() {
                for (var fld in options) {
                    jQuery(this).attr("plugin_submitter_" + fld, options[fld]);
                }
                new $.submitter(this, options, arg);
            });
            return;
        }
    });

    $.submitter = function(item, options, arg) {
        var myName = item.name;
        jQuery(item).val(options.defaulttext);
        var pos = jQuery(item).offset();
        if (typeof(options) == "string") {
            var methodName = options;
            options = {};
            for (var fld in $.submitter.defaults) {
                options[fld] = jQuery(item).attr("plugin_submitter_" + fld);
            }
            // methods
        } else {
            jQuery(item).focus(function() {
                if (this.value == options.defaulttext) {
                    this.value = "";
                }
            });
            var params = (options.extraparams ? options.extraparams : {} );
            jQuery("img[ref='" + myName + "'][func='submit']").click(function() {
                params['text'] = jQuery(item).val();
                redirect(options.page, "", params, false);
            });
        }

        $.submitter.defaults = {
            page : ""
        }
    }
})(jQuery);
